package code;
/**
 * 
 * @author
 * 
 * This class represents the item info.
 * It contains all the information of a product item.
 */
public class ItemInfo {
	private String productName;// product's name
	private double price;// positive double
	private String rfidTagNumber;// encodes the radio frequency for scanning the item
	private String originalLocation;// encodes the original shelf position of the item
	private String currentLocation;// represents the location of the item at the current time

	public ItemInfo(){
		
	}
	
	/**
	 * 
	 * @return the product name
	 */
	public String getProductName() {
		return productName;
	}

	/**
	 * 
	 * @param productName   the product name to set
 	 */
	public void setProductName(String productName) {
		this.productName = productName;
	}

	/**
	 * 
	 * @return the product's price
	 */
	public double getPrice() {
		return price;
	}

	/**
	 * 
	 * @param price  the price to set
	 * @throws PriceNegativeException when price is negative
	 */
	public void setPrice(double price) throws PriceNegativeException {
		if (price <= 0) {
			throw new PriceNegativeException("Price is negative!");
			// when price is negative throws this exception
		}
		this.price = price;
	}

	/**
	 * 
	 * @return the RFID number
	 */
	public String getRfidTagNumber() {
		return rfidTagNumber;
	}

	/**
	 * 
	 * @param rfidTagNumber  the RFID number to set
	 * @throws RfidTagNumberLengthException when rfidTagNumber's length is not 9
	 * @throws RfidTagNumberNotHexException when rfidTagNumber is not in hexadecimal format
	 */
	public void setRfidTagNumber(String rfidTagNumber)
			throws RfidTagNumberLengthException, RfidTagNumberNotHexException {
		if (rfidTagNumber.length() != 9) {
			throw new RfidTagNumberLengthException("RfidTagNumber's lenght is not 9!");
		}
		for (int i = 0; i < 9; i++) {
			char tc = rfidTagNumber.charAt(i);
			if (!((tc >= '0' && tc <= '9') || (tc >= 'A' && tc <= 'F') || (tc >= 'a' && tc <= 'f'))) {
				throw new RfidTagNumberNotHexException("RfidTagNumber is not in hexadecimal format!");
			}
		}
		this.rfidTagNumber = rfidTagNumber;
	}

	/**
	 * 
	 * @return product's original location
	 */
	public String getOriginalLocation() {
		return originalLocation;
	}

	/**
	 * 
	 * @param originalLocation  the product's original location to set
	 * @throws OriginalLocationLengthException  when originalLocation's lenght is not 6
	 * @throws OriginalLocationFormatException  when the first character is not 's' 
	 * 											or the last 5 characters are not all digit
	 */
	public void setOriginalLocation(String originalLocation)
			throws OriginalLocationLengthException, OriginalLocationFormatException {
		if (originalLocation.length() != 6) {
			throw new OriginalLocationLengthException("OriginalLocation's lenght is not 6!");
		}
		if (!(originalLocation.charAt(0) == 's' || originalLocation.charAt(0) == 'S')) {
			throw new OriginalLocationFormatException("The first character is not 's'!");
		}
		for (int i = 1; i < 6; i++) {
			char tc = originalLocation.charAt(i);
			if (!(tc >= '0' && tc <= '9')) {
				throw new OriginalLocationFormatException("The last 5 characters are not all digit!");
			}
		}
		this.originalLocation = originalLocation;
		this.currentLocation = originalLocation;
	}
	/**
	 * 
	 * @return  the product's current location
 	 */
	public String getCurrentLocation() {
		return currentLocation;
	}

	/**
	 * 
	 * @param currentLocation   the product's current location to set
	 * @throws LocationFormatException  when currentLocation is in wrong format
	 */
	public void setCurrentLocation(String currentLocation) throws LocationFormatException {
		Util.checkPostionFormat(currentLocation);
		this.currentLocation = currentLocation;
	}

}
